import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-30
 * Time: 11:05
 */
public class Test {
    public static int[] sortedSquares(int[] nums) {
        //双指针
        int left = 0;
        int right = nums.length-1;
        int[] arr = new int[nums.length];
        int index = arr.length-1;
        while(left <= right){
            if(nums[left] * nums[left] > nums[right] * nums[right]){
                arr[index--] = nums[left]*nums[left];
                left++;
            }else{
                arr[index--] = nums[right]*nums[right];
                right--;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] nums = {-4,-1,0,3,10};
        System.out.println(Arrays.toString(sortedSquares(nums)));
    }
    public static void main6(String[] args) {
        String s1 ="hello";
        String s2 = new String("hello");
        System.out.println(s1 == s2); // false
    }
    public static void main5(String[] args) {
        String s1 = "hello";
        System.out.println(s1.length());

        int[] array = {1,2,3,4};
        System.out.println(array.length);
    }
    public static void main4(String[] args) {
        String s1 = String.format("%d-%d-%d",2002,06,24);
        System.out.println(s1);
    }
    public static void main3(String[] args) {
        String  s1 = "hello";
        char[] ch = s1.toCharArray();
        System.out.println(ch[1]);
    }


    public static boolean canMakeArithmeticProgression(int[] arr) {
        //先排序
        Arrays.sort(arr);
        //判断是否为等差
        if(arr.length == 2) return true;
        for(int i = 1; i < arr.length-1; i++){
            if(arr[i+1] - arr[i] != arr[i] - arr[i-1]){
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        //int[] nums = {1,2,4};
        int[] nums = {-3,3,9};
        //int[] nums = {13,12,-12,9,9,16,7,-10,-20,0,18,-1,-20,-10,-8,15,15,16,2,15};
        System.out.println(canMakeArithmeticProgression(nums));
    }
}
